import { defineStore } from "pinia";
import { getMenus } from "@/api/modules/user";
import { generateRouter } from "@/utils";
import { MeunState } from "../interface";
import { getShowMenuList } from "@/utils";

export const useMenuStore = defineStore({
  id: "menu",
  state: (): MeunState => ({
    menusList: []
  }),
  getters: {
    // 菜单权限列表 ==> 左侧菜单栏渲染，需要剔除 isHide == true
    showMenuListGet: state => getShowMenuList(state.menusList)
  },
  actions: {
    /** 获取侧边栏菜单 */
    async getMenus() {
      const { data } = await getMenus();
      this.menusList = generateRouter(data);
    }
  }
});
